package com.tran.app.screen

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
import com.tran.app.viewmodel.DropScreenVM

//老师的申请解除选课
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun DropScreen(padding: Modifier, navCotroller: NavHostController) {
    Scaffold(modifier = Modifier.fillMaxSize(), topBar = {
        TopAppBar(title = { Text(text = "申请信息") },
            navigationIcon = {
                IconButton(onClick = { navCotroller.popBackStack() }) {
                    Icon(imageVector = Icons.Default.ArrowBack, contentDescription = "back")
                }
            })
    }) { it ->
        val  vm :DropScreenVM = viewModel()
        val uiState = vm.uiData.collectAsState()
            LazyColumn(modifier = Modifier.padding(it)) {
                items(uiState.value.list){
                    Column(modifier = Modifier
                        .padding(start = 10.dp, end = 10.dp)
                        .fillMaxWidth()
                        .drawBehind {
                            drawRect(
                                color = androidx.compose.ui.graphics.Color.Black, // 选择你需要的颜色
                                topLeft = Offset.Zero,
                                size = this.size,
                                style = Stroke(width = 1.dp.toPx())
                            )
                        }
                        .padding(top = 10.dp, bottom = 10.dp, start = 10.dp), horizontalAlignment = Alignment.Start) {
                        Text(text = "课程名:"+it.course.name)
                        Text(text = "学生姓名:"+it.user.realName)
                        Text(text = "系:"+it.user.kind)
                        Text(text = "学生班级:"+it.user.grade)
                        Row {
                            Button(onClick = {
                                vm.agree(it)
                            }) {
                                    Text(text = "同意")
                            }
                            Button(onClick = {
                                vm.refuse(it)
                            }) {
                                Text(text = "驳回")
                            }
                        }
                    }
                }
            }

    }
}
